<template>
  <a-modal
    v-model="visible"
    :centered="true"
    width=70%
    title="表单预览"
    ok-text="关闭"
    cancel-text=""
    :maskClosable="true"
    :footer="null"
    @cancel="onClose" @ok="onClose">
    <!-- 表单区域 -->
    <fm-generate-antd-form
      v-if="jsonData"
      :data="jsonData"
      :remote="remoteFuncs"
      :value="editData"
      :remote-option="dynamicData"
      ref="GenerateForm"
    >
    </fm-generate-antd-form>
  </a-modal>
</template>
<script>
export default {
  name: 'ViewForm',
  data () {
    return {
      visible: false,
      jsonData: {},
      editData: {},
      remoteFuncs: {},
      dynamicData: {},
      loading: false
    }
  },
  methods: {
    onClose () {
      this.visible = false
      this.$emit('close')
    },
    onOpen (data) {
      this.visible = true
      this.jsonData = JSON.parse(data.formJson)
      // 强制刷新，否则更新的jsonData可能无法写入GenerateForm
      this.$nextTick(() => this.$refs.GenerateForm.refresh())
    }
  }
}
</script>
